<template>
<div>
    <Form :model="formCustom" :label-width="80">
        <FormItem label="订单号" prop="order_num">
            <Input type="text" v-model="formCustom.order_num" :disabled="true"></Input>
        </FormItem>
        <FormItem label="商品类型" prop="type">
            <Input type="text" v-model="formCustom.typeValue" :disabled="true"></Input>
        </FormItem>
        <FormItem label="商品名称" prop="name">
            <Input type="text" v-model="formCustom.commit_info.name" :disabled="true"></Input>
        </FormItem>
        <FormItem label="图片" prop="head" v-for="i in formCustom.commit_info.imgs">
            <img  :src="i" width="50" height="50"/>
        </FormItem>
        <FormItem label="商品简介" prop="desc">
            <Input type="text" v-model="formCustom.commit_info.intro" :disabled="true"></Input>
        </FormItem>
        <FormItem label="发布者" prop="desc">
            <Input type="text" v-model="formCustom.publish_user.nickname" :disabled="true"></Input>
        </FormItem>
        <FormItem label="购买者者" prop="desc">
            <Input type="text" v-model="formCustom.buy_user.nickname" :disabled="true"></Input>
        </FormItem>
        <FormItem label="下单时间" prop="sort">
            <Input type="text" v-model="formCustom.timeValue" :disabled="true"></Input>
        </FormItem>
        <FormItem label="订单转态" prop="sort">
            <Input type="text" v-model="values[formCustom.status]" :disabled="true"></Input>
        </FormItem>
        <FormItem>
            <!--<Button type="primary" @click="handleSubmit">Submit</Button>-->
        </FormItem>
    </Form>
</div>
</template>

<script>
    import util from '../libs/util';
    export default {
        created() {
           this.reqBody = this.$route.query;
           this.loadData(this.reqBody);
        },
        data () {
            return {
                formCustom : {},
                reqBody: {},
                values : ["待支付", "支付失败", "待领取", "待归还", "", "已经完成", "已取消"]
            }
        },
        methods: {

            loadData(reqBody) {
                var that = this;
                this.$http.post(util.baseURL+"order/getOrderInfo",reqBody,
                    {emulateJSON: true})
                    .then(
                        (response)=>{
                            if(response.data.data) {
                               //this.$Message.info("更新成功！");
                               //this.$router.push("/index/advertisement");
                               that.processData(response.data.data[0]);
                            } else {
                               this.$Message.error("获取失败！");
                            }
                        },
                        (error)=>{
                            this.$Message.error("获取失败！");
                        }
                );
            },

            processData(data) {
                // 添加商品类别值
                if (data.type == 1) {
                    data.typeValue = "享堂集市";
                }
                if (data.type == 2) {
                    data.typeValue = "享堂学院";
                    data.commit_info.name = data.commit_info.topic;
                    data.commit_info.intro = data.commit_info.topic_intro;
                }
                if (data.type == 3) {
                    data.typeValue = "享堂书院";
                }
                // 图片处理
                var temp = data.commit_info.head.split(";");
                data.commit_info.imgs = [];
                for (var i=0; i<temp.length-1; i++) {
                    data.commit_info.imgs.push(temp[i]);
                }
                // 时间处理
                data.timeValue = this.formatDateTime(data.time*1000);
                console.log(data);
                this.formCustom = data;
                //console.log(data);
            },

            handleSubmit () {
              
            },

            formatDateTime(inputTime) {
                var date = new Date(inputTime);
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? ('0' + m) : m;
                var d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                var h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                var minute = date.getMinutes();
                var second = date.getSeconds();
                minute = minute < 10 ? ('0' + minute) : minute;
                second = second < 10 ? ('0' + second) : second;
                return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
            },

        }
    }
</script>